<!-- 短信登录 - smsLogin  -->
<template>
  <view>
    <!-- 标题栏 -->
    <view class="head-box ss-m-b-60">
      <view class="ss-flex ss-m-b-20">
        <view class="head-title-active ss-m-r-40" style="cursor: pointer" @tap="showAuthModal('accountLogin')"
          >账号登录</view
        >
        <view class="head-title-active head-title-line ss-m-r-40" style="cursor: pointer" @tap="showAuthModal('smsLogin')">短信登录</view>
        <view class="head-title head-title-line">
          扫码登录
        </view>
      </view>
    </view>

    <!-- 表单项 -->
    <iframe style="width: 100%; height: 400px; overflow: hidden" scrolling="no" id="wechatauth" :src="state.wechaturl"></iframe>
  </view>
</template>

<script setup>
  import { computed, watch, ref, reactive, unref } from 'vue';
  import {
    onLoad,
  } from '@dcloudio/uni-app';
  import sheep from '@/sheep';
  import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';

  const smsLoginRef = ref(null);

  const emits = defineEmits(['onConfirm']);

  const props = defineProps({
    agreeStatus: {
      type: Boolean,
      default: false,
    },
  });

  // 数据
  const state = reactive({
    wechaturl: '', // 手机号输入完毕

  });

  // 2.短信登录
  async function smsLoginSubmit() {
    const validate = await unref(smsLoginRef)
      .validate()
      .catch((error) => {
        console.log('error: ', error);
      });
    if (!validate) return;

    if (!props.agreeStatus) {
      emits('onConfirm', true);
      sheep.$helper.toast('请勾选同意');
      return;
    }
    const { code } = await sheep.$api.user.smsLogin(state.model);
    if (code === 1) {
      closeAuthModal();
    }
  }
  onLoad((options)=>{
    state.wechaturl = 'https://wkadmin.jhpress.com/index.php/third/connect/wechat.html?url='+window.location.href;
  });
</script>

<style lang="scss" scoped>
  @import '../index.scss';
</style>
